﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Nop.Admin.Models.ShowCase;
using Nop.Services.Catalog;
using Nop.Web.Framework.Controllers;

namespace Nop.Admin.Controllers
{

    [AdminAuthorize]
    public class ShowCaseController : Controller
    {
        private readonly IProductService _productService;

        public ShowCaseController(IProductService productService)
        {
            _productService = productService;
        }

        public ActionResult Index()
        {
            var showCaseListModel = new ShowCaseListModel();
            var p  = _productService.GetShowCaseProductsOnHomePage();

            foreach (var showCaseProduct in p)
            {
                var showCaseListItemModel = new ShowCaseListItemModel()
                    {
                        Id=showCaseProduct.Id,
                        Title = showCaseProduct.Title,
                        ShowCaseListItemProductModels =
                            showCaseProduct.Items.Select(c => new ShowCaseListItemProductModel()
                                {
                                    Product = c.Product,
                                    Sort = c.Sort
                                }).ToList()
                    };

                showCaseListModel.ShowCaseListItemModels.Add(showCaseListItemModel);
            }
            return View(showCaseListModel);
        }

        public ActionResult Edit(int id)
        {
            ViewBag.ShowCaseId = id ;
            return View("SaveOrEdit");
        }

        public ActionResult Create()
        {
            return View();
        }

    }
}
